(function( $ ){
    //ONE APP AT A TIME... MAYBE WE COULD CHANGE IT BUT I DONT SEE WHY NOW...
    var methods = {
        init : function( options ) { 
            settings = $.extend( {
                'parent' : celebrio.desktop.getElement()
            }, options);
            data = this.data('celebrioApp');
            if ( ! data ) {
                this.data('celebrioApp', {
                    'parent': settings.parent
                });

            }
            this.celebrioApp('maximize');
            return this;
        },
        minimize : function( ) {
            this.hide();
            //TODO Make this celebrio independent?
            celebrio.applications.setFocus(null);
        },
        
        unminimize : function( ) {
            this.show();
            this.celebrioApp('maximize');
        },
        
        maximize : function( ) {
            data = this.data('celebrioApp');
            if (!data) {
                return;
            }
            this.width($(window).width());
            this.height(data.parent.height());
            this.css({
                'position' : 'absolute', 
                'top' : 0, 
                'left' : 0
            });
        },
        
        destroy : function( ) {

            this.remove();
            data = this.data('celebrioApp');

            // Namespacing FTW
            $(window).unbind('.celebrioApp');
            data.celebrioApp.remove();
            this.removeData('celebrioApp');
        }
    };

    $.fn.celebrioApp = function( method ) {
    
        // Method calling logic
        if ( methods[method] ) {
            return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } else {
            $.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
        }    
  
    };
})( jQuery );